package org.penguin.study.bk.eventbus.controller;

import org.jetbrains.annotations.NotNull;
import org.penguin.study.bk.base.util.IdUtil;
import org.penguin.study.bk.base.vo.Result;
import org.penguin.study.bk.eventbus.EventHelper;
import org.penguin.study.bk.eventbus.event.OrderEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/eventbus")
public class EventBusController {

    @Autowired
    private EventHelper eventHelper;

    @RequestMapping(value = "/createOrder", method = {RequestMethod.GET, RequestMethod.POST})
    public Result<?> createOrderEvent() {
        OrderEvent orderEvent = new OrderEvent();
        orderEvent.setOderId(IdUtil.generateUUID());
        orderEvent.setCustomerId(IdUtil.generateUUID());
        orderEvent.setCustomerName("程英华");
        orderEvent.setGoodNames("代码随想录——跟着Carl学算法、计算之魂 （《数学之美》");
        orderEvent.setPhone("13230190965");

        eventHelper.postEvent(orderEvent);
        return Result.ok("成功发布Eventbus消息。");
    }
}
